---@class TBS.CameraMgr
local CameraMgr = TBS.CreateSingleton("CameraMgr")
local this = CameraMgr
function CameraMgr.OnCreate()
    this.isDestroy = false
    ---@type GameObject
    this.gameObject = nil
    ---@type Camera
    this.camera = nil
    ---@type Camera
    this.cameraBack = nil
    ---@type Camera
    this.cameraDrawing = nil
    ---@type Transform
    this.transform = nil
    ---@type Transform
    this.sceneRoot = nil
    ---@type UnityEngine.RenderTexture
    this.texture = nil
    ---@type Canvas
    this.canvas = nil
    ---@type TBSCameraRender
    this.tbsCameraRender = nil
    this.CreateSceneRoot()
    this.CreateEffCamera()
end
function CameraMgr.OnDestroy()
    if this.texture then
        destroy(this.texture)
    end
    if this.gameObject then
        destroy(this.gameObject)
    end
    if this.sceneRoot then
        destroy(this.sceneRoot.gameObject)
    end
    this.texture = nil
    this.tbsCameraRender = nil
    this.sceneRoot = nil
    this.gameObject = nil
    this.camera = nil
    this.isDestroy = true
end
function CameraMgr.CreateEffCamera()
    if this.gameObject then return end

    resMgr:LoadPrefab("Prefabs/Battle/RenderCamera",function(obj)
        if this.isDestroy then return end
        if this.gameObject then return end
        --this.texture = UnityEngine.RenderTexture.New(Screen.width,Screen.height,0)
        --this.texture.useMipMap = false
        this.gameObject = newObject(obj)
        Util.Lua_SetLocalPositionXYZ(this.gameObject,-150,150,0)
        --local transform = this.gameObject.transform
        this.tbsCameraRender = this.gameObject:GetComponent(typeof(TBSCameraRender))
        this.texture = this.tbsCameraRender:CreateTexture()
        this.camera = this.tbsCameraRender.foreCamera
        this.canvas = this.tbsCameraRender.canvas
        this.tbsCameraRender:SetRender(true,false,false)
        TBS.Battle.LoadCameraDone()
    end)
end
function CameraMgr.CreateSceneRoot()
    local go = GameObject.New("root")
    this.sceneRoot = go.transform
    Util.Lua_SetLocalPositionXYZ(this.sceneRoot,-150,150,0)
    TBS.Battle.SetEffectRoot(this.sceneRoot)
end
function CameraMgr.EnableUltimateCamera(enable)
    if enable then
        this.tbsCameraRender:SetRender(true,true,true)
        this.tbsCameraRender:EnablePostProcess(false)
    else
        this.tbsCameraRender:SetRender(true,false,false)
        this.tbsCameraRender:EnablePostProcess(true)
    end
end
